<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p><a href="https://www.baidu.com" id="baidu">百度</a></p>
    <script src="jquery-3.7.1.min.js"></script>

    <script>
        $(document).ready(function() {
            $("p a").attr("href", "https://www.bilibili.com");
            console.log($("p a").attr("href"));
        }) 
    </script>

    <!-- <script>
        $(document).ready(function() {
            var href = $("p a").attr("href");
            console.log(href);
        })
    </script> -->
</body>
</html>